﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace weba
{
    public partial class kefuchat : System.Web.UI.Page
    {
        public static int ycount =0;
        public static List<youke> lyk = new List<youke>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
           {
               todaymsg();
                binggrid();
           
           }
            
               
           
        }

        private void todaymsg()
        {
            string b = "";
            foreach (youke y in kefuchat.lyk.Where(g => System.DateTime.Now.DayOfYear == (Convert.ToDateTime(g.dtm)).DayOfYear & System.DateTime.Now.Year == (Convert.ToDateTime(g.dtm)).Year).ToList())
            {
                b += y.ykname.ToString() + "于" + y.dtm.ToString() + "说" + "<br />" + y.message + "<br />";

            }
            this.TextArea1.InnerText = b;
        }

        private void binggrid()
        {
            this.GridView1.DataSource = (from g in lyk where (Convert.ToDateTime(g.dtm)).DayOfYear == System.DateTime.Now.DayOfYear & (Convert.ToDateTime(g.dtm)).Year == System.DateTime.Now.Year select new { g.seionid }).Distinct().ToList();
            this.GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox ck1 = GridView1.Rows[i].FindControl("ykck") as CheckBox;
              //  int f = 2;
                if (ck1.Checked == true)
                {
                    kefuchat.lyk.Add(new youke() { ykname = "客服", dtm = System.DateTime.Now.ToString(), seionid = GridView1.DataKeys[i].Value.ToString(), message = this.TextArea2.InnerText });



                }
            }
            //string b = "";
            //foreach (youke y in kefuchat.lyk.ToList())
            //{
            //    b += y.ykname.ToString() + "于" + y.dtm.ToString() + "说" + "<br />" + y.message + "<br />";

            //}
            //this.TextArea1.InnerText = b;
            todaymsg();
            binggrid();
            this.TextArea2.InnerText = "";
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            todaymsg();
            binggrid();
            this.TextArea2.InnerText = "";
        }

       

        protected void Button3_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox ck1 = GridView1.Rows[i].FindControl("ykck") as CheckBox;
                // int f = 2;
                ck1.Checked = true;

            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
           for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                CheckBox ck1 = GridView1.Rows[i].FindControl("ykck") as CheckBox;
                // int f = 2;
                ck1.Checked = false;

            }
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            lyk.Clear();
            mk.Alert("已清理所有聊天记录");
        }
    }
}